package gui;

import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import localhost._8080.metaimage.Client;

public class MiniShellTab extends JPanel implements KeyListener, MouseListener{

	private static final long serialVersionUID = 1L;
	private JTextArea shell;
	private JTextField cmd;
	private JList l;
	
	public MiniShellTab(JList l){
		super();
		this.l=l;
		BorderLayout bd = new BorderLayout();
		this.setLayout(bd);
		shell = new JTextArea("This is a shell - Enter your command in the bottom line");
		this.add(shell,BorderLayout.CENTER);
		shell.setEditable(false);
		cmd = new JTextField("Type your command here");
		cmd.addMouseListener(this);
		cmd.addKeyListener(this);
		this.add(cmd,BorderLayout.PAGE_END);
	}
	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		if (arg0.getKeyChar() == '\n'){
			shell.append("\n"+this.cmd.getText()+"  >>  "+ Client.execute(this.cmd.getText())  );
			SplitPaneDemo.updateLabel(((String)l.getSelectedValue()));
			
			cmd.setText("");
			
		}
	}
	@Override
	public void mouseClicked(MouseEvent arg0) {
		this.cmd.setText("");
	}
	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
